Main site

Built-in Modules > Agline Class

Agline Class

Important: This plugin relies on third-party resources. The resources might change or be discontinued without notice. Ensure you test the plugin extensively before production use, implement error handling with a try-catch block, have a backup shipping rate ready, and reach out to our support with detailed descriptions of any unexpected issues.

Overview

The Agline class is specifically designed to fetch real-time shipping rates for products from Agline.

Class Definition

class Agline {
  constructor(destination) {
    // Class constructor
  }

  async getRates(aglineProducts) {
    // Method to fetch rates
  }
}

Arguments

  • destination (Object): This refers to the "destination" information within the input DATA JSON object accepted by the calculateShippingRates function.

Usage Example

const agline = new Agline(DATA.destination);
const aglineProducts = [
  { agline_sku: "AD383695", quantity: 1 },
  { agline_sku: "AD383698", quantity: 1 },
  // ... more products
];
const rates = await agline.getRates(aglineProducts);

In this example, the Agline class is used to obtain shipping rates for a range of Agline products, each identified by their SKU (agline_sku) and quantity. The getRates method calculates the shipping costs for these products, providing rates in a format consistent with Shopify's shipping rate structure.

Sample AI Prompt

I'd like a shipping rate calculator for items from Agline.
Use the items sku as the Agline product sku.

Sample AI Output

// Import required modules
import { Agline } from "./modules.js";

// Export the calculateShippingRates function
export async function calculateShippingRates(DATA, env) {
  try {
    // Create an instance of the Agline class
    const agline = new Agline(DATA.destination);

    // Prepare Agline products array
    const aglineProducts = DATA.items.map((item) => ({
      agline_sku: item.sku,
      quantity: item.quantity,
    }));

    // Get shipping rates from Agline
    const rates = await agline.getRates(aglineProducts);

    // Return the shipping rates in the expected Shopify format
    return { rates };
  } catch (error) {
    // Handle errors and return an empty rate
    return {
      rates: [
        {
          service_name: "",
          service_code: "",
          total_price: null,
          description: "",
          currency: "",
          min_delivery_date: "",
          max_delivery_date: "",
        },
      ],
    };
  }
}